//
//  RootTabViewController.m
//  MyApp
//
//  Created by liaowentao on 17/3/29.
//  Copyright © 2017年 Haochuang. All rights reserved.
//

#import "RootTabViewController.h"
#import "NJUSTNavigationController.h"
#import "CommonMethods.h"
#import "Define.h"

@interface RootTabViewController ()<UITabBarControllerDelegate>

@end

@implementation RootTabViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self buildUI];
    // Do any additional setup after loading the view.
}

/**构建视图*/
- (void)buildUI{
    
    self.tabBar.translucent     = NO;
    self.tabBar.backgroundImage = [CommonMethods createImageWithColor:[UIColor whiteColor]];
    self.tabBar.shadowImage     = [CommonMethods createImageWithColor:[UIColor grayColor]];
    
    NSArray * normalItems       = @[@"tabBar_schedule_normal", @"tabBar_achievement_normal", @"tabBar_library_normal", @"tabBar_my_normal"];
    NSArray * selectItmes       = @[@"tabBar_schedule_select", @"tabBar_achievement_select", @"tabBar_library_select", @"tabBar_my_select"];
    
    NSArray * controllClass     = @[@"ScheduleVC", @"AchievementVC", @"LibraryBooksVC", @"MyVC"];
    self.delegate               = self;
    NSArray * itemTitles        = @[@"课程表",@"成绩",@"图书馆", @"个人中心"];
    NSMutableArray * controllers = [[NSMutableArray alloc]init];
    for (int i = 0; i < normalItems.count; i++)
    {
        UIViewController * homeview =[[NSClassFromString(controllClass[i]) alloc]init];
        NJUSTNavigationController * navigation =[[NJUSTNavigationController alloc]initWithRootViewController:homeview];
        navigation.tabBarItem.image                     = [[UIImage imageNamed:normalItems[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        navigation.tabBarItem.selectedImage             = [[UIImage imageNamed:selectItmes[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        navigation.tabBarItem.titlePositionAdjustment   = UIOffsetMake(0,-3);
        [controllers addObject:navigation];
        
        // 设置文字的样式
        NSMutableDictionary *textAttrs                  = [NSMutableDictionary dictionary];
        textAttrs[NSForegroundColorAttributeName]       = kTabbarNormalTintColor;
        NSMutableDictionary *selectTextAttrs            = [NSMutableDictionary dictionary];
        selectTextAttrs[NSForegroundColorAttributeName] = kTabbarSelectTintColor;
        [navigation.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
        [navigation.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
        // 设置tabbaritem 的title
        navigation.tabBarItem.title                     = itemTitles[i];
    }
    self.viewControllers = controllers;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
